package de.dhbw.ka.tit09.picsim.ui.model;

import java.util.ArrayList;
import java.util.List;

import de.dhbw.ka.tit09.picsim.model.SourceText;

/**
 * Provider class for the source text table. This class is a singleton.
 * 
 * @author Andreas Bender
 * 
 */
public final class SourceTextTableProvider {

	private List<SourceTextTableElement> elements = new ArrayList<SourceTextTableElement>();

	private static final SourceTextTableProvider INSTANCE = new SourceTextTableProvider();

	private SourceTextTableProvider() {

	}

	/**
	 * Returns the instance of the table provider.
	 * 
	 * @return the provider instance
	 */
	public static SourceTextTableProvider getInstance() {
		return INSTANCE;
	}

	/**
	 * Sets the source text table elements.
	 * 
	 * @param elements the table elements
	 */
	public void setElements(List<SourceTextTableElement> elements) {
		this.elements = elements;
	}

	/**
	 * Returns the source text table elements.
	 * 
	 * @return the table elements
	 */
	public List<SourceTextTableElement> getElements() {
		return elements;
	}

	/**
	 * Creates a new source text table.
	 * 
	 * @param sourceTextList the source text elements
	 * @return the new source text table elements
	 */
	public List<SourceTextTableElement> createSourceTextTable(
			List<SourceText> sourceTextList) {
		elements = new ArrayList<SourceTextTableElement>();

		for (SourceText sourceTextLine : sourceTextList) {
			elements.add(new SourceTextTableElement(sourceTextLine.getText(),
					sourceTextLine.isCommand()));
		}

		return elements;
	}
}
